<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String contextPath=request.getContextPath();
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+contextPath;
pageContext.setAttribute("basePath",basePath);
request.setAttribute("contextPath", contextPath);
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<title>Insert title here</title>
	<script type="text/javascript" src="${basePath }/js/jquery-1.7.2.js"></script>
	<script type="text/javascript">
		function valid(){
			var loginName=$("#loginName").val();
			if(""==loginName){
				//TODO
				return false;
			}
			/* 此处我把input换成submit就成功了  */
			var button=$("input[type=submit]");
			$.ajax({
				url:"${contextPath}/check/"+loginName,
				type:"get",
				success:function(o){
					if(o && o.result){
						console.log("可以登录");
						$("#errTip").hide();
						button.removeAttr("disabled");
					}else{
						console.log("不可以登录");
						$("#loginName").focus();
						button.attr("disabled","true");
						$("#errTip").show();
					}
				},
				error:function(o){
					alert(o);
				}
			});
		}
	</script>
</head>
<body>
	<form action="${contextPath }/login" method="post">
		<table width="80%" border="1">
			<tr>
	            <td>loginName</td>
	            <td><input type="text" value="" name="loginName" id="loginName" onblur="valid()"/></td>
		        <span id="errTip" name="errTip" style="color: red; display: none">此用户不存在，请重新输入</span>
	        </tr>
	        <tr>
	            <td>password</td>
	            <td><input type="text" value="" name="password"/></td>
	        </tr>
		</table>
		<br/>
        <input type="submit" value="login"/>
	</form>
</body>
</html>